package com.example.multithread;

class MyThreadR implements Runnable {


    private String name;

    public MyThreadR(String name) {
        this.name = name;
    }
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(""+this.name+" 线程执行，当前的循环次数为: " + i);
        }
    }
}

public class MyThread2 {

    public static void main(String[] args) {
        Thread thread = new Thread(new MyThreadR("线程A"));
        Thread thread2 = new Thread(new MyThreadR("线程B"));
        Thread thread3 = new Thread(new MyThreadR("线程C"));
        thread.start();
        thread2.start();
        thread3.start();


        // lambda 形式
        for (int i = 0; i < 3; i++) {
            String name = "Thread-" + i + "线程对象";
            new Thread(() -> {
                for (int j = 0; j < 10; j++) {
                    System.out.println(""+name+" 线程执行，当前的循环次数为 : " + j);
                }
            }).start();
        }
    }
}
